/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.config.web.login;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.config.entity.login.ConfigLoginQQ;
import com.thinkgem.jeesite.modules.config.service.login.ConfigLoginQQService;

/**
 * QQ登录配置Controller
 * @author JiangYongKang
 * @version 2016-12-14
 */
@Controller
@RequestMapping(value = "${adminPath}/config/login/configLoginQQ")
public class ConfigLoginQQController extends BaseController {

	@Autowired
	private ConfigLoginQQService configLoginQQService;
	
	@ModelAttribute
	public ConfigLoginQQ get(@RequestParam(required=false) String id) {
		ConfigLoginQQ entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = configLoginQQService.get(id);
		}
		if (entity == null){
			entity = new ConfigLoginQQ();
		}
		return entity;
	}
	
	@RequiresPermissions("config:login:configLoginQQ:view")
	@RequestMapping(value = {"list", ""})
	public String list(ConfigLoginQQ configLoginQQ, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<ConfigLoginQQ> page = configLoginQQService.findPage(new Page<ConfigLoginQQ>(request, response), configLoginQQ); 
		model.addAttribute("page", page);
		return "modules/config/login/configLoginQQList";
	}

	@RequiresPermissions("config:login:configLoginQQ:view")
	@RequestMapping(value = "form")
	public String form(ConfigLoginQQ configLoginQQ, Model model) {
		model.addAttribute("configLoginQQ", configLoginQQ);
		return "modules/config/login/configLoginQQForm";
	}

	@RequiresPermissions("config:login:configLoginQQ:edit")
	@RequestMapping(value = "save")
	public String save(ConfigLoginQQ configLoginQQ, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, configLoginQQ)){
			return form(configLoginQQ, model);
		}
		configLoginQQService.save(configLoginQQ);
		addMessage(redirectAttributes, "保存QQ登录配置成功");
		return "redirect:"+Global.getAdminPath()+"/config/login/configLoginQQ/?repage";
	}
	
	@RequiresPermissions("config:login:configLoginQQ:edit")
	@RequestMapping(value = "delete")
	public String delete(ConfigLoginQQ configLoginQQ, RedirectAttributes redirectAttributes) {
		configLoginQQService.delete(configLoginQQ);
		addMessage(redirectAttributes, "删除QQ登录配置成功");
		return "redirect:"+Global.getAdminPath()+"/config/login/configLoginQQ/?repage";
	}

}